package com.dingli.DAO;

import com.dingli.entity.Person;
import com.dingli.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class RegisterAndLoginDAO {
    private QueryRunner runner = new QueryRunner(DataSourceUtil.getDataSource());

    public Person login(String name, String password) throws SQLException {
        String sql = "SELECT * FROM person where account = ? and password = ?";
        return runner.query(sql, new BeanHandler<>(Person.class), name, password);
    }

    public int logout(String name, String password) throws SQLException {
        int flag = 0;
        String insertSql = "INSERT INTO person (account, password) VALUES (?, ?)";
        flag = runner.update(insertSql, name, password);
        return flag;
    }
}


